<template>
  <div class="post_project">
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form :model="form" ref="form" label-width="100px">
        <el-form-item label="实际结项日期">
          <el-date-picker v-model="form.endDate" size="mini" type="date" style="width:100%" value-format="yyyy-MM-dd" placeholder='请选择实际结项日期'></el-date-picker>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" size="mini" @click="cancel">取消</el-button>
        <el-button type="primary" size="mini" @click="submitForm">确认结项</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { updateProjects, getProjects } from "@/api/business/project/projects";
export default {
  name: 'post_project',
  data() {
    return {
      open: false,
      title: '结项',
      form: {
        pName: null,
        pSgdw: null,
        pStatus: null,
        startDate: null,
        endDate: null,
        pXmjl: null,
        pLxfs: null,
        pMoney: null,
      },
    }
  },
  methods: {
    init(row) {
      this.open = true;
      this.rest()
      this.getProjectsDetail(row)
    },
    /** 获取详情 */
    getProjectsDetail(row) {
      const id = row.id
      getProjects(id).then(response => {
        console.log(response)
        this.form = response.data;
        this.form.endDate = null;
      });
    },
    rest() {
      this.form = {
        pName: null,
        pSgdw: null,
        pStatus: null,
        startDate: null,
        endDate: null,
        pXmjl: null,
        pLxfs: null,
        pMoney: null,
      };
      this.resetForm("form");
    },
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.pStatus = '5'
          updateProjects(this.form).then(response => {
            this.$modal.msgSuccess("结项成功");
            this.open = false;
            this.$parent.getList()
          });

        }
      });
    },
    cancel() {
      this.open = false;
      this.rest()
    }
  }
}
</script>

<style>
</style>